<template>
  <div class="reply-container">
    <!-- 导航栏 -->
    <van-nav-bar :title="replyComment.reply_count?`${replyComment.reply_count}条回复`:'暂无回复'">
      <van-icon color="#000" slot="left" name="cross" @click="$emit('close')" />
    </van-nav-bar>
    <div class="scroll-warp">

      <!-- 评论内容 -->
      <comment-item :comment="replyComment" />
      <!-- 回复内容 -->
      <van-cell title="全部回复" />
      <!-- 文章评论 -->
      <comment-article :source="replyComment.com_id" type="c" :list="commentList" />
    </div>

    <!-- 底部回复 -->
    <div class="post-warp">
      <van-button round @click="isReplyComment=true">评论</van-button>
    </div>
    <!-- 发表评论弹层 -->
    <van-popup v-model="isReplyComment" position="bottom" :style="{ height: '20%' }">
      <pop-field :target="replyComment.com_id" :articleId="$route.params.articleId" @postComment="onPostReply" />
    </van-popup>
  </div>
</template>

<script>
// 导入评论组件
import CommentItem from '@/components/comment-item'
import CommentArticle from './comment-article.vue'
// 导入写评论组件
import PopField from './pop-field.vue'
export default {
  name: 'Comment-Reply',
  props: {
    replyComment: {
      type: Object,
      require: true
    }
  },
  data () {
    return {
      commentList: [],
      type: this.type,
      isReplyComment: false
    }
  },
  methods: {
    // 监听 回复评论
    onPostReply (e) {
      this.replyComment.reply_count++
      this.isReplyComment = false
      this.commentList.unshift(e.data.new_obj)
    }
  },
  computed: {},
  watch: {},
  filters: {},
  components: { CommentItem, CommentArticle, PopField },
  created () { },
  mounted () { }
}
</script>

<style lang='less' scoped>
.reply-container {
  .scroll-warp {
    width: 100%;
    position: absolute;
    top: 82px;
    bottom: 100px;
    overflow: scroll;
  }

  .post-warp {
    width: 100%;
    height: 100px;
    position: fixed;
    bottom: 0;
    background-color: #46a2fc;
    display: flex;
    justify-content: center;
    align-items: center;
    .van-button {
      width: 640px;
      height: 70px;
    }
  }
}
</style>
